<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改学生信息</title>
</head>
<script type="text/javascript">
function updateStudent(stuID,majorID){

        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("get","/modifystudent?stuID="+stuID+"&majorID="+majorID,true);
        xmlhttp.onreadystatechange=function ()
        { if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                try {
                    location.href="student.html";
                } catch (error) {
                    console.error( error);
                    alert("解析数据失败，请检查服务器返回的数据格式");
                }
            } else {
                console.error("请求失败，状态码:", xmlhttp.status, "状态文本:", xmlhttp.statusText);
                alert("修改失败");
            }
        }
        }


        xmlhttp.send();



}



</script>


<body>
<h1>学生信息详情</h1>
<div class="info-container">
    <div class="info-item">
        <label class="info-label">学号：</label>
        <label id="stuID-display"></label>
    </div>
    <div class="info-item">
        <label class="info-label">专业 ID：</label>
        <input type="text" id="majorID-input">
    </div>
    <div class="info-item">
        <label class="info-label">入学时间：</label>
        <label id="enrollTime-display"></label>
    </div>
    <div class="info-item">
        <label class="info-label">身份证号：</label>
        <label id="sfzh-display"></label>
    </div>
</div>
<button onclick="getAndUpdateStudent()">保存修改</button>

<script>
    // 获取 URL 中的查询字符串
    const queryString = window.location.search;
    // 创建 URLSearchParams 对象来解析查询字符串
    const urlParams = new URLSearchParams(queryString);

    // 获取各个参数的值
    const stuID = urlParams.get('stuID');
    const majorID = urlParams.get('majorID');
    const enrollTime = urlParams.get('enrollTime');
    const sfzh = urlParams.get('sfzh');

    // 将参数值显示在对应的 HTML 元素中
    document.getElementById('stuID-display').textContent = stuID;
    document.getElementById('majorID-input').value = majorID;
    document.getElementById('enrollTime-display').textContent = enrollTime;
    document.getElementById('sfzh-display').textContent = sfzh;


    function getAndUpdateStudent() {
        // 获取输入框中的值
        const updatedMajorID = document.getElementById('majorID-input').value;
        // 调用 updateStudent 函数发送请求
        updateStudent(stuID, updatedMajorID);
    }
</script>
</body>
</html>